<template>
  <CommonModule
    :columns="columns"
    :fetchList="fetchList"
    :nativeName="nativeName"
  />
</template>
<script>
import CommonModule from './CommonModule';
import {
  PURCHASE_INFO_COLUMNS,
  PURCHASE_INFO_MULTI_COLUMNS,
  NATIVE_NAMES
} from './constants';
import { getDetailByRecordNoService } from '@/api/commodity/commodityAccessManage/commodityAdd';
export default {
  components: {
    CommonModule
  },
  props: {
    nativeName: {
      type: String,
      default: ''
    },
  },
  data () {
    return {
      columns: [],
    }
  },
  watch: {
    nativeName: {
      handler (val) {
        this.updateColumns(val)
      },
      immediate: true
    }
  },
  methods: {
    // 更新表格列
    updateColumns (nativeName) {
      if (nativeName == NATIVE_NAMES.PurchaseInfo) {
        this.columns = PURCHASE_INFO_COLUMNS
      }
      if (nativeName == NATIVE_NAMES.PurchaseInfoMulti) {
        this.columns = PURCHASE_INFO_MULTI_COLUMNS
      }
    },
    // 更新表格数据
    async fetchList (data, loadingFn) {
      const res = await getDetailByRecordNoService(data, loadingFn)
      return {
        results: res?.retData?.results ?? [],
        totalNum: res?.retData?.totalNum
      }
    }
  }
}
</script>
